<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"A-4");
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "changeadmin")) {
$cekimage = substr($_FILES['logo']['type'],0,5);
$tmpname = $_FILES['logo']['tmp_name'];
$destfile = "logo.jpg";
if($cekimage =='image') {
copy($tmpname,$destfile);
}
$logo ="logo.jpg";
  $updateSQL = sprintf("UPDATE gl_company SET npwp=%s, alamat=%s, telp=%s, fax=%s, logo=%s, perusahaan=%s, cabang=%s, norek=%s, atasnama=%s, a_kas=%s, a_hut=%s, a_piu=%s, a_beb=%s, a_paj=%s, a_hpp=%s, a_pend=%s, r_kontrak=%s, r_kir=%s, r_stnk=%s, r_asuransi=%s, r_servise=%s WHERE id=%s",
                       GetSQLValueString($_POST['npwp'], "text"),
					   GetSQLValueString($_POST['alamat'], "text"),
                       GetSQLValueString($_POST['telp'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($logo, "text"),
                       GetSQLValueString($_POST['perusahaan'], "text"),
					   GetSQLValueString($_POST['cabang'], "text"),
					   GetSQLValueString($_POST['norekening'], "text"),
					   GetSQLValueString($_POST['atasnama'], "text"),
					   GetSQLValueString($_POST['kasbank'], "text"),
					   GetSQLValueString($_POST['hutang'], "text"),
					   GetSQLValueString($_POST['piutang'], "text"),
					   GetSQLValueString($_POST['beban'], "text"),
					   GetSQLValueString($_POST['pajak'], "text"),
					   GetSQLValueString($_POST['hpp'], "text"),
					   GetSQLValueString($_POST['pendapatan'], "text"),
					   GetSQLValueString($_POST['r_kontrak'], "int"),
					   GetSQLValueString($_POST['r_kir'], "int"),
					   GetSQLValueString($_POST['r_stnk'], "int"),
					   GetSQLValueString($_POST['r_asuransi'], "int"),
					   GetSQLValueString($_POST['r_servise'], "int"),
					   GetSQLValueString($_POST['id'], "int")); //echo $updateSQL;

  mysql_select_db($database_con_gl, $con_gl);
  $Result1 = mysql_query($updateSQL, $con_gl) or die(mysql_error());
echo "<script type=\"text/javascript\">window.location=\"index.php?component=perusahaan\";</script>";
}


mysql_select_db($database_con_gl, $con_gl);
$query_getadmin = "SELECT * FROM gl_company";
$getadmin = mysql_query($query_getadmin, $con_gl) or die(mysql_error());
$row_getadmin = mysql_fetch_assoc($getadmin);
$totalRows_getadmin = mysql_num_rows($getadmin);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_1 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=2 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_1 = mysql_query($query_ak_1, $con_gl) or die(mysql_error());
$row_ak_1 = mysql_fetch_assoc($ak_1);
$totalRows_ak_1 = mysql_num_rows($ak_1);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_2 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=7 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_2 = mysql_query($query_ak_2, $con_gl) or die(mysql_error());
$row_ak_2 = mysql_fetch_assoc($ak_2);
$totalRows_ak_2 = mysql_num_rows($ak_2);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_3 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=6 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_3 = mysql_query($query_ak_3, $con_gl) or die(mysql_error());
$row_ak_3 = mysql_fetch_assoc($ak_3);
$totalRows_ak_3 = mysql_num_rows($ak_3);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_4 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=10 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_4 = mysql_query($query_ak_4, $con_gl) or die(mysql_error());
$row_ak_4 = mysql_fetch_assoc($ak_4);
$totalRows_ak_4 = mysql_num_rows($ak_4);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_5 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=9 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_5 = mysql_query($query_ak_5, $con_gl) or die(mysql_error());
$row_ak_5 = mysql_fetch_assoc($ak_5);
$totalRows_ak_5 = mysql_num_rows($ak_5);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_6 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=4 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_6 = mysql_query($query_ak_6, $con_gl) or die(mysql_error());
$row_ak_6 = mysql_fetch_assoc($ak_6);
$totalRows_ak_6 = mysql_num_rows($ak_6);

mysql_select_db($database_con_gl, $con_gl);
$query_ak_7 = "SELECT gl_klas.klasifikasi, gl_akun.id, gl_akun.akun FROM gl_klas, gl_akun WHERE gl_klas.tipe=5 AND gl_akun.klasifikasi = gl_klas.kd ORDER BY gl_klas.klasifikasi, gl_akun.id";
$ak_7 = mysql_query($query_ak_7, $con_gl) or die(mysql_error());
$row_ak_7 = mysql_fetch_assoc($ak_7);
$totalRows_ak_7 = mysql_num_rows($ak_7);
?>
<link type="text/css" rel="stylesheet" href="css/jquery.wysiwyg.css" />
<script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
<script type="text/javascript">
$(function()
  {
      $('#alamat').wysiwyg();
	  //$('#b_alamat').wysiwyg();
  });
</script>
<h1>Info Perusahaan  </h1>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="changeadmin" id="changeadmin">
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" class="datatable">
    <tr>
      <td colspan="2"><a name="info" id="info"><strong><a href="#info">Info Perusahaan</a> | <a href="#rekening">Rekening Bank</a> | <a href="#reminder">Remider Notice</a></strong></td>
    </tr>
    <tr>
      <td width="175" align="right" valign="top" bgcolor="#FFFFFF">Produk ID : </td>
      <td width="703" bgcolor="#FFFFFF">acc-07/2010/100
      <input name="id" type="hidden" id="id" value="<?php echo $row_getadmin['id']; ?>" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">NPWP : </td>
      <td bgcolor="#FFFFFF"><label>
      <input name="npwp" type="text" id="npwp" value="<?php echo $row_getadmin['npwp']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Nama Perusahaan : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="perusahaan" type="text" id="perusahaan" value="<?php echo $row_getadmin['perusahaan']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Alamat : </td>
      <td bgcolor="#FFFFFF"><label>
        <textarea name="alamat" cols="85" rows="5" id="alamat"><?php echo $row_getadmin['alamat']; ?></textarea>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Telp : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="telp" type="text" id="telp" value="<?php echo $row_getadmin['telp']; ?>" size="20" maxlength="20" />
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Fax : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="fax" type="text" id="fax" value="<?php echo $row_getadmin['fax']; ?>" size="20" maxlength="20" />
      </label></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Logo : </td>
      <td bgcolor="#FFFFFF"><label> <img src="<?php echo $row_getadmin['logo']; ?>" /><br />
        <input name="logo" type="file" id="logo" />
      </label></td>
    </tr>

    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF"><strong>Rekening Bank</strong><a name="rekening" id="rekening"></a> </td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Cabang : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="cabang" type="text" id="cabang" value="<?php echo $row_getadmin['cabang']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">No.Rekening : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="norekening" type="text" id="norekening" value="<?php echo $row_getadmin['norek']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Atas Nama  : </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="atasnama" type="text" id="atasnama" value="<?php echo $row_getadmin['atasnama']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF"><strong>Akun Default </strong><a name="akun" id="akun"></a></td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Kas / Bank : </td>
      <td valign="top" bgcolor="#FFFFFF"><label>
        <select name="kasbank" id="kasbank" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_kas']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_1['id']?>"<?php if (!(strcmp($row_ak_1['id'], $row_getadmin['a_kas']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_1['id']?> - <?php echo $row_ak_1['akun']?></option>
          <?php
} while ($row_ak_1 = mysql_fetch_assoc($ak_1));
  $rows = mysql_num_rows($ak_1);
  if($rows > 0) {
      mysql_data_seek($ak_1, 0);
	  $row_ak_1 = mysql_fetch_assoc($ak_1);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">HPP : </td>
      <td valign="top" bgcolor="#FFFFFF"><label>
        <select name="hpp" id="hpp" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_hpp']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_6['id']?>"<?php if (!(strcmp($row_ak_6['id'], $row_getadmin['a_hpp']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_6['id']?> - <?php echo $row_ak_6['akun']?></option>
          <?php
} while ($row_ak_6 = mysql_fetch_assoc($ak_6));
  $rows = mysql_num_rows($ak_6);
  if($rows > 0) {
      mysql_data_seek($ak_6, 0);
	  $row_ak_6 = mysql_fetch_assoc($ak_6);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Pendapatan : </td>
      <td valign="top" bgcolor="#FFFFFF"><label>
        <select name="pendapatan" id="pendapatan" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_pend']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_7['id']?>"<?php if (!(strcmp($row_ak_7['id'], $row_getadmin['a_pend']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_7['id']?> - <?php echo $row_ak_7['akun']?></option>
          <?php
} while ($row_ak_7 = mysql_fetch_assoc($ak_7));
  $rows = mysql_num_rows($ak_7);
  if($rows > 0) {
      mysql_data_seek($ak_7, 0);
	  $row_ak_7 = mysql_fetch_assoc($ak_7);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Hutang : </td>
      <td valign="top" bgcolor="#FFFFFF"><label>
        <select name="hutang" id="hutang" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_hut']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_2['id']?>"<?php if (!(strcmp($row_ak_2['id'], $row_getadmin['a_hut']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_2['id']?> - <?php echo $row_ak_2['akun']?></option>
          <?php
} while ($row_ak_2 = mysql_fetch_assoc($ak_2));
  $rows = mysql_num_rows($ak_2);
  if($rows > 0) {
      mysql_data_seek($ak_2, 0);
	  $row_ak_2 = mysql_fetch_assoc($ak_2);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Piutang : </td>
      <td valign="top" bgcolor="#FFFFFF"><label>
        <select name="piutang" id="piutang" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_piu']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_3['id']?>"<?php if (!(strcmp($row_ak_3['id'], $row_getadmin['a_piu']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_3['id']?> - <?php echo $row_ak_3['akun']?></option>
          <?php
} while ($row_ak_3 = mysql_fetch_assoc($ak_3));
  $rows = mysql_num_rows($ak_3);
  if($rows > 0) {
      mysql_data_seek($ak_3, 0);
	  $row_ak_3 = mysql_fetch_assoc($ak_3);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Beban :</td>
      <td bgcolor="#FFFFFF"><label>
        <select name="beban" id="beban" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_beb']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_4['id']?>"<?php if (!(strcmp($row_ak_4['id'], $row_getadmin['a_beb']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_4['id']?> - <?php echo $row_ak_4['akun']?></option>
          <?php
} while ($row_ak_4 = mysql_fetch_assoc($ak_4));
  $rows = mysql_num_rows($ak_4);
  if($rows > 0) {
      mysql_data_seek($ak_4, 0);
	  $row_ak_4 = mysql_fetch_assoc($ak_4);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Pajak : </td>
      <td bgcolor="#FFFFFF"><label>
        <select name="pajak" id="pajak" style="width:225px;>
          <option value="" <?php if (!(strcmp("", $row_getadmin['a_paj']))) {echo "selected=\"selected\"";} ?>>Not Set</option>
          <?php
do {  
?><option value="<?php echo $row_ak_5['id']?>"<?php if (!(strcmp($row_ak_5['id'], $row_getadmin['a_paj']))) {echo "selected=\"selected\"";} ?>><?php echo $row_ak_5['id']?> - <?php echo $row_ak_5['akun']?></option>
          <?php
} while ($row_ak_5 = mysql_fetch_assoc($ak_5));
  $rows = mysql_num_rows($ak_5);
  if($rows > 0) {
      mysql_data_seek($ak_5, 0);
	  $row_ak_5 = mysql_fetch_assoc($ak_5);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF"><strong>Remider Notice </strong><a name="remider" id="reminder"></a></td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Kontrak :</td>
      <td bgcolor="#FFFFFF"><label>
        <input name="r_kontrak" type="text" id="r_kontrak" value="<?php echo $row_getadmin['r_kontrak']; ?>" size="5" maxlength="5" onkeyup="javascript: if(isNaN(this.value)){alert('Field harus diisi angka');this.value='0';}" />
      </label>
        hari</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">KIR :</td>
      <td bgcolor="#FFFFFF"><label>
        <input name="r_kir" type="text" id="r_kir" value="<?php echo $row_getadmin['r_kir']; ?>" size="5" maxlength="5" onkeyup="javascript: if(isNaN(this.value)){alert('Field harus diisi angka');this.value='0';}" />
      </label>
        hari</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">STNK :</td>
      <td bgcolor="#FFFFFF"><label>
        <input name="r_stnk" type="text" id="r_stnk" value="<?php echo $row_getadmin['r_stnk']; ?>" size="5" maxlength="5" onkeyup="javascript: if(isNaN(this.value)){alert('Field harus diisi angka');this.value='0';}" />
      </label>
        hari</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Asuransi :</td>
      <td bgcolor="#FFFFFF"><label>
        <input name="r_asuransi" type="text" id="r_asuransi" value="<?php echo $row_getadmin['r_asuransi']; ?>" size="5" maxlength="5" onkeyup="javascript: if(isNaN(this.value)){alert('Field harus diisi angka');this.value='0';}" />
        </label>
        hari</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Service :</td>
      <td bgcolor="#FFFFFF"><label>
	   <input name="r_servise" type="text" id="r_servise" value="<?php echo $row_getadmin['r_servise']; ?>" size="5" maxlength="5" onkeyup="javascript: if(isNaN(this.value)){alert('Field harus diisi angka');this.value='0';}" /> 
       </label>
	   hari </td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF"><input name="id" type="hidden" id="id" value="<?php echo $row_getadmin['id']; ?>"></td>
      <td bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan">
      </label></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="changeadmin">
</form>
<?php
mysql_free_result($ak_6);

mysql_free_result($ak_7);
?>
